FROM php:7.2-fpm

# 安装基础依赖
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip \
    libzip-dev \
    bash-completion \
    vim \
    librdkafka1 \
    librdkafka-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    && rm -rf /var/lib/apt/lists/*

# 安装 PHP 扩展
RUN docker-php-ext-install \
    pdo \
    pdo_mysql \
    mbstring \
    xml \
    ctype \
    bcmath \
    zip

# 安装 rdkafka 扩展
RUN pecl channel-update pecl.php.net && \
    pecl install rdkafka-3.1.3 && \
    docker-php-ext-enable rdkafka

# 配置 PHP 错误日志
# COPY php72/conf.d/error-logging.ini /usr/local/etc/php/conf.d/error-logging.ini

# 安装 Composer 2
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# 创建目录并设置权限
RUN mkdir -p /var/www/.composer/cache && \
    chown -R www-data:www-data /var/www/.composer && \
    chmod -R 777 /var/www/.composer

# 创建项目目录
RUN mkdir -p /var/www/projects && \
    chown -R www-data:www-data /var/www/projects && \
    chmod -R 777 /var/www/projects

# 设置工作目录
WORKDIR /var/www/projects

# 切换到 www-data 用户
USER www-data

# 配置 Composer 使用 HTTPS
RUN composer config -g secure-http false
